<template>
    <div class="public-survey-wrapper">
      <div class="public-survey-wrap">
        <!--banner图-->
        <div class='banner-wrap'>
          <div class="swiper-container" style="height: 100%;">
            <div class="swiper-wrapper">
              <div class="swiper-slide"  v-for="(item, index) in bannerList" :key="index">
                <a :href="item.link">
                  <img :src="baseUrl.CDNimgUrl + item.image">
                </a>
              </div>
            </div>
            <!-- Add Pagination -->
            <div class="swiper-pagination"></div>
          </div>
        </div>
        <!--列表-->
        <div class="public-survey-list-wrap">
          <van-list
            v-model="isUploading"
            :finished="isUpfinished"
            :finished-text=" labsList.length === 0 ? '暂无数据' : '没有更多了' "
            @load="onLoad"
          >
            <van-row style="margin-bottom: 12px" v-for="(item,index) in labsList" :key="index">
              <router-link :to="{path:baseUrl.detail,query:{id:item.id}}">
                <van-col span="10">
                  <div class="list-image">
                    <img :src="baseUrl.CDNimgUrl + item.image">
                  </div>
                </van-col>
                <van-col span="13" offset="1">
                  <h4 class="list-title">{{item.title}}</h4>
                  <p class="quoted-price">官方报价：&yen;{{item.price}}</p>
                  <div class="clearfix">
                    <span class="fl">数量：{{item.number}}</span>
                    <span class="fr">{{item.total}}人申请</span>
                  </div>
                  <div v-if="new Date(item.result_stamps).getTime() > parseInt(new Date().getTime()/1000)">
                    <van-button type="primary" size="large" class="list-button" v-if="item.status === null">免费申请</van-button>
                    <van-button type="primary" size="large" class="list-button" v-if="item.status === 1">申请中</van-button>
                    <van-button type="primary" size="large" class="list-button" v-if="item.status === 2">试用中</van-button>
                    <van-button type="primary" size="large" class="list-button unsigned" v-if="item.status === 3">未中签</van-button>
                    <van-button type="primary" size="large" class="list-button unsigned" v-if="item.status === 5">已结束</van-button>
                  </div>
                  <div v-if="new Date(item.result_stamps).getTime() <= parseInt(new Date().getTime()/1000)">
                    <van-button type="primary" size="large" class="list-button unsigned" >已结束</van-button>
                  </div>
                </van-col>
              </router-link>
            </van-row>
          </van-list>
        </div>
      </div>
      <footer-nav :oactive="active"></footer-nav>
    </div>
</template>

<script>
  import ajax from '../../module/ajax/public'
  import FooterNav from '@/components/FooterNav'
  import { Row, Col, Cell, Button,Icon, List } from 'vant'

    export default {
        name: "PublicSurvey",
        components: {
          FooterNav,
          [Row.name]: Row,
          [Col.name]: Col,
          [Cell.name]: Cell,
          [Button.name]: Button,
          [Icon.name]: Icon,
          [List.name]: List
        },
        mounted(){
          this.getLabsData()

        },
        data(){
            return{
              active: 1,
              baseUrl:{
                'CDNimgUrl':this.GLOBAL.CDNimgUrl,
                'detail':'/public-survey-detail'
              },
              bannerList: [],
              labsList:[],
              isUploading: false,
              isUpfinished: false,
              page:0,
            }
        },
        methods:{
            getLabsData(){
              ajax.doAction({
                url:'/lab/banner',
                type: 'GET',
                successCallback:(data)=>{
                  // console.log(data)
                  let datas = data.data
                  this.bannerList = datas
                  this.$nextTick(() => {
                    new Swiper('.swiper-container', {
                      pagination: '.swiper-pagination',
                      paginationClickable: true,
                      autoplay: 3000,
                      autoplayDisableOnInteraction: false,
                      loop: true
                    })
                  })
                },
                errorCallback: (data)=> {
                  console.log('请求失败');
                }
              })
            },
            getLabsList(){
              this.page++;
              ajax.doAction({
                url:`/labs?page=${this.page}`,
                type: 'GET',
                successCallback:(data)=>{
                  // console.log(data)
                  let datas = data.data
                  this.isUploading = false
                  if(datas.length >0){
                    this.labsList = this.labsList.concat(datas)
                  }else{
                    this.isUpfinished = true;
                  }
                },
                errorCallback: (data)=> {
                  console.log('请求失败');
                }
              })
            },
            onLoad () {
              // console.log('上拉加载'+this.page);
              this.getLabsList()
            },
        }
    }
</script>

<style>
  .public-survey-wrapper .public-survey-wrap{
    padding-bottom: 55px;
  }
  .public-survey-wrapper .public-survey-wrap .banner-wrap{
  height: 137px;
  overflow: hidden;
}
.public-survey-wrap .banner-wrap .swiper-pagination-bullet-active{
  background: #fff;
}
.public-survey-wrapper .public-survey-wrap .public-survey-list-wrap{
  padding: 20px 12px 0;
}
.public-survey-wrap .public-survey-list-wrap .list-image{
  height: 114px;
  border-radius: 5px;
  overflow: hidden;
}
.public-survey-wrap .public-survey-list-wrap h4{
  font-size: 15px;
  line-height: 20px;
  font-weight: bold;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  height: 40px;
  word-break: break-all;
}
.public-survey-wrap .public-survey-list-wrap p{
  font-size: 12px;
  margin-bottom: 5px;
  color: #333;
 }
.public-survey-wrap .public-survey-list-wrap span{
  font-size: 12px;
  color: #333;
}
.public-survey-wrap .public-survey-list-wrap  .list-button{
  height: 30px;
  line-height: 30px;
  background-color: #ef8a26;
  border:none;
  border-radius: 5px;
  font-size: 12px;
  margin-top: 5px;
}
.public-survey-wrap .public-survey-list-wrap  .list-button.unsigned{
  background-color: #888;
}
.public-survey-wrap .public-survey-list-wrap  .list-button .van-button__text{
  color:#fff
}
</style>
